#!/usr/bin/python

import os

# list the active simulations
active_sims = []

broken_sims = []

for isim in active_sims:
   snapdir = isim+"Data/Snapshots/"
   #print " snapdir = ", snapdir
   if os.path.exists(snapdir+"this_update"):
       os.system("mv "+snapdir+"this_update "+snapdir+"last_update")
   else:
       os.system("touch "+snapdir+"last_update")

   os.system("stat "+snapdir+"info.txt | grep Modify | awk '{print $3}' > "+snapdir+"this_update")
   os.system("diff "+snapdir+"last_update "+snapdir+"this_update > "+snapdir+"update_check")
   os.system("stat "+snapdir+"update_check | grep Size | awk '{print $2}' > "+snapdir+"update_size")

   size = 0

   fff = open(snapdir+"update_size")
   l = long(fff.readlines()[0])
   fff.close()

   size = l

   if size==0:
       # If size == 0 then info.txt is not being updated regularly
       # Write the offending directory to the master list in my public_html
       # thisdir = os.environ.get('PWD') + '/' + snapdir
       thisdir = snapdir
       broken_sims.append(thisdir)

   # clean up
   os.system("\\rm "+snapdir+"update_check")
   os.system("\\rm "+snapdir+"update_size")

# write the list of broken sims to a web-viewable file
fff=open("/home/ssi/rcrain/public_html/telemetry/broken_sims.txt","w")

from time import asctime

if len(broken_sims)==0: 
    fff.write("%s\n"%asctime())     
    fff.write(" - all simulations running ok\n")
else: 
    fff.write("%s\n"%asctime())     
    fff.write("Following simulations are not updating:\n")
    for b in broken_sims:
        fff.write(" - %s\n"%b)

fff.close()

